package com.zjff.myshop.util;

import cn.hutool.core.map.MapUtil;
import com.zjff.myshop.common.Constants;
import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
/**
 * 分页查询参数
 */
public class PageQuery extends LinkedHashMap<String, Object> {
    //当前页码
    private int page;
    //每页条数
    private int limit;

    public PageQuery(Map<String, Object> map) {
        this.putAll(map);
        //分页参数
        this.page = MapUtil.getInt(map, "page", 1);//默认页号1
        this.limit = MapUtil.getInt(map, "limit", Constants.PAGE_LIMIT);//默认页大小
        if (this.page == 0) {
            this.page = 1;
        }
        if (this.limit == 0) {
            this.limit = Constants.PAGE_LIMIT;
        }
        this.put("start", (page - 1) * limit);
        this.put("page", page);
        this.put("limit", limit);
    }

}
